﻿using Microsoft.AspNetCore.Mvc.Controllers;
using Syspetro.Core.Extensions;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace Syspetro.Core.DynamicApi
{
    public class DynamicApiControllerFeatureProvider : ControllerFeatureProvider
    {
        //custom controller checker
        protected override bool IsController(TypeInfo typeInfo)
        {
            var type = typeInfo.AsType();

            if (!typeof(IDynamicApi).IsAssignableFrom(type) ||
                !typeInfo.IsPublic || typeInfo.IsAbstract || typeInfo.IsGenericType)
            {
                return false;
            }

            if (AttributeHelper.GetSingleAttributeOrDefaultByFullSearch<NonDynamicApiAttribute>(typeInfo) != null)
            {
                return false;
            }

            return true;
        }
    }
}
